package com.xm.servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wxm.servlet.BaseServlet;
import com.xm.dao.LianXiDaoImpl;
import com.xm.entity.Banners;
import com.xm.entity.Comdetail;
import com.xm.entity.LianXi;
import com.xm.uti.Result;

/**
 * Servlet implementation class LianXiServletAdmin
 */
@WebServlet("/admin/LianXiServletAdmin")
public class LianXiServletAdmin extends BaseServlet {
	LianXiDaoImpl lxDao=new LianXiDaoImpl();
	
	/**
	   * 查列表
	   * 
	   * @param request
	   * @param response
	   * @throws ServletException
	   * @throws IOException
	   */
		
	  public void getLianxiList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

	    // 调用dao层的方法，获取所有员工
		  ArrayList<LianXi> lianxi=lxDao.getCom();
	     
	    // 调用结果工具类，将数据返回
	    String res = Result.toClient(0, "联系列表", lianxi,lianxi.size());
	    
	    PrintWriter out = resp.getWriter(); // 获取输出对象
	    out.print(res); // 输出数据
	    out.flush(); // 刷新
	    out.close(); // 关闭

	  }
	  /**
		 * 修改联系信息
		 */
		public void updateLianxi(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			// 1.接收客户端传来的参数(字符串类型)
			String tels = req.getParameter("tels");
			String qqHao = req.getParameter("qqHao");
			String weiXin = req.getParameter("weiXin");
			String gongZhongHao = req.getParameter("gongZhongHao");
			String id = req.getParameter("id");
			
			// 2.调用dao层的方法，修改
			boolean res = lxDao.updateLIanxi(new LianXi(Integer.valueOf(id), tels, qqHao, weiXin, gongZhongHao));
			System.out.println("要修改的联系表对象是" + res);
			// 3、讲数据返回到页面上
			PrintWriter out = resp.getWriter();

			if (res) {
				out.write(Result.toClient(0, "修改成功"));
			} else {
				out.write(Result.toClient(1, "修改失败"));
			}
			// 将数据封装为layui需要的格式
			out.flush();
			out.close();
		}
	  
	  

}
